
<style media="screen">
td{
    white-space: nowrap
}
</style>

<Widget:show bdcls="no-padding" col="12" title="【{$tb}】表信息" >
    <Widget:action >
    &nbsp;&nbsp;
    <a data-ajax-dialog href="{:U("Db/addField?tb=$tb")}" class="btn blue">新增字段</a>
    <a href="{:U("Db/index?tb=$tb")}" class="btn blue">修改表</a>
    <a href="#" class="btn blue">重新排序</a>
    <a ajax-confirmation href="{:U("Db/deleteFrom?tb=$tb&pk=all")}" class="btn red ">重置</a>
    <a data-ajax-dialog href="{:U("Db/copyFrom?tb=$tb&source=$scene")}" class="btn btn-info">复制场景</a>
    </Widget:action>
    
    <Widget:action >
    &nbsp;&nbsp;
    <a class="btn btn-sm red" data-pjax href="{:U("Db/table?f=$f&tb=$tb")}">返回</a>

        <a data-ajax href="{:U("Db/creatM?name=$tb&f=$f")}" class="btn green">生成模型</a>
        <a data-ajax href="{:U("Db/creatC?name=$tb&f=$f")}" class="btn green">生成控制器</a>
    </Widget:action>
    <Widget:action >
    <select data-value="{$Think.get.tb}" name="tb" class="form-control input-sm" >
        <volist name="tables" id="tt">
            <option value="{$tt.table_name}">{$tt.table_name}</option>
        </volist>
    </select>
    </Widget:action>
    <div class="table-scrollable">
        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th colspan="10" class="center aligned">表单设计</th>
                <th colspan="3" class="center aligned">字段结构</th>
            </tr>
            <tr>
                <th >字段名</th>
                <th >标签</th>
                <th >显示</th>
                <th >类型</th>
                <th >输入格式</th>
                <th >提示</th>
                <th >必填</th>
                <th >默认值</th>
                <th >自动完成</th>
                <th >列</th>

                <th >类型</th>
                <th >长度</th>
                <th >注释</th>
                <th width="100">#</th>
            </tr>
            </thead>
            <tbody>
                <volist name="table" id="tbs">
                <tr>
                    <td>{$tbs.field}</td>
                    <td><a href="#" editable-input data-name="label" data-type="text" data-pk="{$tbs.field}" >{$tbs.label}</a></td>
                    <td><a href="#" editable-select-isshow data-name="isshow" data-type="select" data-value="{$tbs.isshow}" data-pk="{$tbs.field}" ></a></td>
                    <td><a href="#" editable-select-ipttype data-name="ipttype" data-type="select" data-value="{$tbs.ipttype}" data-pk="{$tbs.field}" ></a>
                    <in name="tbs[ipttype]" value="select">
                    &nbsp;
                        <a href="#" data-value="{$tbs.list}" data-name="list"editable-textarea data-type="textarea" data-pk="{$tbs.field}">
                        <Ui:icon name="list" />
                        </a>
                    </in>
                    </td>
                    <td><a href="#" editable-select-format data-name="format" data-type="select" data-value="{$tbs.format}" data-pk="{$tbs.field}" ></a></td>
                    <td><a href="#" editable-input data-name="tip" data-type="text" data-pk="{$tbs.field}" ></a></td>
                    <td><a href="#" editable-select-valid data-name="valid" data-type="select" data-value="{$tbs.valid}" data-pk="{$tbs.field}" ></a></td>
                    <td><a href="#" editable-input data-name="defvalue" data-type="text" data-pk="{$tbs.field}" >{$tbs.defvalue}</a></td>
                    <td><a href="#" editable-select-auto data-name="auto" data-type="select" data-value="{$tbs.auto}" data-pk="{$tbs.field}" >{$tbs.auto}</a></td>
                    <td><a href="#" editable-input data-name="iptCols" data-type="text" data-pk="{$tbs.field}" >{$tbs.iptCols}</a></td>
                    <td>
                        <select data-value="{$tbs[type]}" class="form-control input-sm" name="type">
                            {:fieldTypeOpt()}
                        </select>
                    </td>
                    <td>{$tbs.length}</td>
                    <td>
                        <a href="#" editable-input data-name="comment" data-type="text" data-pk="{$tbs.field}" >{$tbs.comment}</a>
                    </td>
                    <td>
                        <neq name="tbs[pos]" value="$table_count">
                        <a data-pk="{$tbs.field}" data-arrow="moveDown" href="#"><i class="glyphicon glyphicon-arrow-down"></i></a>
                        </neq>
                        <neq name="tbs[pos]" value="0">
                        <a data-pk="{$tbs.field}" data-arrow="moveUp" href="#"><i class="glyphicon glyphicon-arrow-up"></i></a>
                        </neq>
                        <a data-ajax href="{:U("Table/deleteField?tb=$tb&field=$tbs[field]")}"><i class="glyphicon glyphicon-remove"></i></a>
                    </td>
                </tr>
                </volist>
            </tbody>
        </table>
    </div>
</Widget:show>

<script type="text/javascript">
$(function(){

    var url = "{:U("Table/updateFrom?tb=$tb&scene=$scene&f=$f")}";
    $.fn.editable.defaults.url = url;


    $('[editable-input]').editable();
    $('[editable-select-ipttype]').editable({
        prepend: "请选择",
        source: [
            {value: 'input', text: 'input'},
            {value: 'password', text: 'password'},
            {value: 'select', text: 'select'},
            {value: 'number', text: 'number'},
            {value: 'date', text: 'date'},
            {value: 'time', text: 'time'},
            {value: 'dic', text: '字典'},
            {value: 'datetime', text: 'datetime'},
            {value: 'hidden', text: 'hidden'},
            {value: 'checkbox', text: 'checkbox'},
            {value: 'textarea', text: 'textarea'},
            {value: 'umeditor', text: 'umeditor'},
            {value: 'file', text: 'file'},
            {value: 'fileinput', text: 'fileinput'},
            {value: 'upimg', text: 'upimg'},
        ]
    });

    $('[editable-select-format]').editable({
        prepend: "文本",
        source: [
            {value: 'text', text: '文本'},
            {value: 'number', text: '数字'},
            {value: 'email', text: '邮箱'},
            {value: 'url', text: '网址'},
            {value: 'date', text: '日期'},
            {value: 'time', text: '时间'},
            {value: 'datetime', text: '日期+时间'},
        ]
    });

    $('[editable-select-auto]').editable({
        prepend: "请选择",
        source: [
            {value: '', text: '不处理'},
            {value: 'toDate', text: 'toDate'},
            {value: 'toDatetime', text: 'toDatetime'},
            {value: 'strtotime', text: 'strtotime'},
            {value: 'cut', text: 'cut'},
            {value: 'url', text: 'url'},
            {value: 'link', text: 'link'},
        ]
    });

    $('[editable-select-isshow]').editable({
        prepend: "隐藏",
        source: [
            {value: '1', text: '显示'},
            {value: '0', text: '隐藏'},
        ]
    });

    $('[editable-select-valid]').editable({
        prepend: "选填",
        source: [
            {value: 'required', text: '必填'},
            {value: '', text: '选填'},
        ]
    });


    $('[data-editable]').editable();

    $('[editable-textarea]').editable({
        display: function(value, sourceData) {
            $(this).html('<i class="glyphicon glyphicon-th-list "></i>');
        }
    });

    $('select[name=tb]').on('change',function(){
        var tb = $(this).val();
        var container = $('[pjax-content]');
        var url = window.location.href;
        url = U('tb',tb,url);
        $.pjax({url: url, container: container})
    })

    $('[data-arrow]').on('click',function(e){
        e.preventDefault();
        var name = $(this).attr('data-arrow');
        var value = 'NO';
        var pk = $(this).attr('data-pk');
        $.get(url,{name:name,pk:pk,value:value},function(){
            var container = $('[pjax-content]');
            $.pjax.reload(container);
            // var u = window.location.href;
            // window.location.href = u;
        });
    })
})
</script>
